function charIsLetter(ch: string): boolean {
    return ch.toLowerCase() != ch.toUpperCase();
}
function charIsNumber(ch: string): boolean {
    return ch >= "0" && ch <= "9";
}
function charIs(ch: string, chars: string): boolean {
    for (var i = 0; i < chars.length; i++) {
        if (ch == chars.charAt(i)) return true;
    }
    return false;
}
function charIsLetterNumberOr(ch: string, chars: string) {
    for (var i = 0; i < chars.length; i++) {
        if (ch == chars.charAt(i)) return true;
    }
    return ch >= "0" && ch <= "9" || ch.toLowerCase() != ch.toUpperCase();
}
function isHere(a: string, pos: Pos, b: string): boolean {
    if (a.length < b.length + pos.pos) return false;
    for (var i = 0; i < b.length; i++) {
        if (a.charAt(pos.pos + i) != b.charAt(i))
            return false;
    }
    return true;
}
function trim(s: string, pos: Pos) {
    while (s.charAt(pos.pos) == " " && pos.pos < pos.endpos) pos.pos++;
}
function trimc(s: string, pos: Pos, letters : string) {
    while(charIs(s.charAt(pos.pos), letters) && pos.pos < pos.endpos) pos.pos++;
}
function readTo(script: string, pos: Pos, chars: string): string {
    var ns = pos.pos;
    while (!charIs(script.charAt(pos.pos), chars)) { pos.pos++; }
    return script.substring(ns, pos.pos);
}
function shallowCopy<T>(v: T): T {
    var res = {};
    for (var p in v) {
        res[p] = v[p];
    }
    return <T>res;
}

class Pos {
    constructor(public endpos: number, public pos: number = 0) { }
}